<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta content="en" name="language">
	<title>quantize</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link media="screen" href="../docutils-api.css" type="text/css" rel="stylesheet">

</head>

<body>

<div class="banner">
<img src="../images/gm-107x76.png" alt="GraphicMagick logo" width="107" height="76" />
<span class="title">GraphicsMagick</span>
<form action="http://www.google.com/search">
  <input type="hidden" name="domains" value="www.graphicsmagick.org" />
  <input type="hidden" name="sitesearch" value="www.graphicsmagick.org" />
<span class="nowrap"><input type="text" name="q" size="25" maxlength="255" />&nbsp;<input type="submit" name="sa" value="Search" /></span>
</form>
</div>


<div class="navmenu">
<ul>
  <li><a href="../index.html">Home</a></li>
  <li><a href="../project.html">Project</a></li>
  <li><a href="../download.html">Download</a></li>
  <li><a href="../README.html">Install</a></li>
  <li><a href="../Hg.html">Source</a></li>
  <li><a href="../NEWS.html">News</a> </li>
  <li><a href="../utilities.html">Utilities</a></li>
  <li><a href="../programming.html">Programming</a></li>
  <li><a href="../reference.html">Reference</a></li>
</ul>
</div>

<main id="quantize">
<h1 class="title">quantize</h1>
<p class="subtitle" id="reduce-the-number-of-colors-in-an-image">Reduce the number of colors in an image</p>
<div class="contents topic" id="contents">
<p class="topic-title">Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#clonequantizeinfo" id="id21">CloneQuantizeInfo</a></p></li>
<li><p><a class="reference internal" href="#compressimagecolormap" id="id22">CompressImageColormap</a></p></li>
<li><p><a class="reference internal" href="#destroyquantizeinfo" id="id23">DestroyQuantizeInfo</a></p></li>
<li><p><a class="reference internal" href="#getimagequantizeerror" id="id24">GetImageQuantizeError</a></p></li>
<li><p><a class="reference internal" href="#getquantizeinfo" id="id25">GetQuantizeInfo</a></p></li>
<li><p><a class="reference internal" href="#grayscalepseudoclassimage" id="id26">GrayscalePseudoClassImage</a></p></li>
<li><p><a class="reference internal" href="#mapimage" id="id27">MapImage</a></p></li>
<li><p><a class="reference internal" href="#mapimages" id="id28">MapImages</a></p></li>
<li><p><a class="reference internal" href="#orderedditherimage" id="id29">OrderedDitherImage</a></p></li>
<li><p><a class="reference internal" href="#quantizeimage" id="id30">QuantizeImage</a></p></li>
<li><p><a class="reference internal" href="#quantizeimages" id="id31">QuantizeImages</a></p></li>
</ul>
</div>
<section id="clonequantizeinfo">
<h1><a class="toc-backref" href="#id21">CloneQuantizeInfo</a></h1>
<section id="synopsis">
<h2>Synopsis</h2>
<pre class="literal-block"><a class="reference external" href="../api/types.html#quantizeinfo">QuantizeInfo</a> *CloneQuantizeInfo( const <a class="reference external" href="../api/types.html#quantizeinfo">QuantizeInfo</a> *quantize_info );</pre>
</section>
<section id="description">
<h2>Description</h2>
<p>CloneQuantizeInfo() makes a duplicate of the given quantize info structure,
or if quantize info is NULL, a new one.</p>
<p>The format of the CloneQuantizeInfo method is:</p>
<pre class="literal-block"><a class="reference external" href="../api/types.html#quantizeinfo">QuantizeInfo</a> *CloneQuantizeInfo( const <a class="reference external" href="../api/types.html#quantizeinfo">QuantizeInfo</a> *quantize_info );</pre>
<p>A description of each parameter follows:</p>
<dl class="simple">
<dt>clone_info:</dt>
<dd><p>Method CloneQuantizeInfo returns a duplicate of the given
quantize info, or if image info is NULL a new one.</p>
</dd>
<dt>quantize_info:</dt>
<dd><p>a structure of type info.</p>
</dd>
</dl>
</section>
</section>
<section id="compressimagecolormap">
<h1><a class="toc-backref" href="#id22">CompressImageColormap</a></h1>
<section id="id1">
<h2>Synopsis</h2>
<pre class="literal-block">void CompressImageColormap( <a class="reference external" href="../api/types.html#image">Image</a> *image );</pre>
</section>
<section id="id2">
<h2>Description</h2>
<p>CompressImageColormap() compresses an image colormap by removing any
duplicate or unused color entries.</p>
<p>The format of the CompressImageColormap method is:</p>
<pre class="literal-block">void CompressImageColormap( <a class="reference external" href="../api/types.html#image">Image</a> *image );</pre>
<p>A description of each parameter follows:</p>
<dl class="simple">
<dt>image:</dt>
<dd><p>The image.</p>
</dd>
</dl>
</section>
</section>
<section id="destroyquantizeinfo">
<h1><a class="toc-backref" href="#id23">DestroyQuantizeInfo</a></h1>
<section id="id3">
<h2>Synopsis</h2>
<pre class="literal-block">DestroyQuantizeInfo( <a class="reference external" href="../api/types.html#quantizeinfo">QuantizeInfo</a> *quantize_info );</pre>
</section>
<section id="id4">
<h2>Description</h2>
<p>DestroyQuantizeInfo() deallocates memory associated with an QuantizeInfo
structure.</p>
<p>The format of the DestroyQuantizeInfo method is:</p>
<pre class="literal-block">DestroyQuantizeInfo( <a class="reference external" href="../api/types.html#quantizeinfo">QuantizeInfo</a> *quantize_info );</pre>
<p>A description of each parameter follows:</p>
<dl class="simple">
<dt>quantize_info:</dt>
<dd><p>Specifies a pointer to an QuantizeInfo structure.</p>
</dd>
</dl>
</section>
</section>
<section id="getimagequantizeerror">
<h1><a class="toc-backref" href="#id24">GetImageQuantizeError</a></h1>
<section id="id5">
<h2>Synopsis</h2>
<pre class="literal-block">unsigned int GetImageQuantizeError( <a class="reference external" href="../api/types.html#image">Image</a> *image );</pre>
</section>
<section id="id6">
<h2>Description</h2>
<p>GetImageQuantizeError() measures the difference between the original
and quantized images.  This difference is the total quantization error.
The error is computed by summing over all pixels in an image the distance
squared in RGB space between each reference pixel value and its quantized
value.  These values are computed:</p>
<p>o mean_error_per_pixel:  This value is the mean error for any single
pixel in the image.</p>
<p>o normalized_mean_square_error:  This value is the normalized mean
quantization error for any single pixel in the image.  This distance
measure is normalized to a range between 0 and 1.  It is independent
of the range of red, green, and blue values in the image.</p>
<p>o normalized_maximum_square_error:  This value is the normalized
maximum quantization error for any single pixel in the image.  This
distance measure is normalized to a range between 0 and 1.  It is
independent of the range of red, green, and blue values in your image.</p>
<p>The format of the GetImageQuantizeError method is:</p>
<pre class="literal-block">unsigned int GetImageQuantizeError( <a class="reference external" href="../api/types.html#image">Image</a> *image );</pre>
<p>A description of each parameter follows.</p>
<dl class="simple">
<dt>image:</dt>
<dd><p>Specifies a pointer to an Image structure;  returned from
ReadImage.</p>
</dd>
</dl>
</section>
</section>
<section id="getquantizeinfo">
<h1><a class="toc-backref" href="#id25">GetQuantizeInfo</a></h1>
<section id="id7">
<h2>Synopsis</h2>
<pre class="literal-block">GetQuantizeInfo( <a class="reference external" href="../api/types.html#quantizeinfo">QuantizeInfo</a> *quantize_info );</pre>
</section>
<section id="id8">
<h2>Description</h2>
<p>GetQuantizeInfo() initializes the QuantizeInfo structure.</p>
<p>The format of the GetQuantizeInfo method is:</p>
<pre class="literal-block">GetQuantizeInfo( <a class="reference external" href="../api/types.html#quantizeinfo">QuantizeInfo</a> *quantize_info );</pre>
<p>A description of each parameter follows:</p>
<dl class="simple">
<dt>quantize_info:</dt>
<dd><p>Specifies a pointer to a QuantizeInfo structure.</p>
</dd>
</dl>
</section>
</section>
<section id="grayscalepseudoclassimage">
<h1><a class="toc-backref" href="#id26">GrayscalePseudoClassImage</a></h1>
<section id="id9">
<h2>Synopsis</h2>
<pre class="literal-block">void GrayscalePseudoClassImage( <a class="reference external" href="../api/types.html#image">Image</a> *image );</pre>
</section>
<section id="id10">
<h2>Description</h2>
<p>GrayscalePseudoClassImage converts an image to a PseudoClass
grayscale representation with an (optionally) compressed and sorted
colormap. Colormap is ordered by increasing intensity.</p>
<p>The format of the GrayscalePseudoClassImage method is:</p>
<pre class="literal-block">void GrayscalePseudoClassImage( <a class="reference external" href="../api/types.html#image">Image</a> *image );</pre>
<p>A description of each parameter follows:</p>
<dl class="simple">
<dt>image:</dt>
<dd><p>The image.</p>
</dd>
<dt>optimize_colormap:</dt>
<dd><p>If true, produce an optimimal (compact) colormap.</p>
</dd>
</dl>
</section>
</section>
<section id="mapimage">
<h1><a class="toc-backref" href="#id27">MapImage</a></h1>
<section id="id11">
<h2>Synopsis</h2>
<pre class="literal-block">unsigned int MapImage( <a class="reference external" href="../api/types.html#image">Image</a> *image, const <a class="reference external" href="../api/types.html#image">Image</a> *map_image,
                       const unsigned int dither );</pre>
</section>
<section id="id12">
<h2>Description</h2>
<p>MapImage() replaces the colors of an image with the closest color from a
reference image.</p>
<p>The format of the MapImage method is:</p>
<pre class="literal-block">unsigned int MapImage( <a class="reference external" href="../api/types.html#image">Image</a> *image, const <a class="reference external" href="../api/types.html#image">Image</a> *map_image,
                       const unsigned int dither );</pre>
<dl class="simple">
<dt>image:</dt>
<dd><p>Specifies a pointer to an Image structure.</p>
</dd>
<dt>map_image:</dt>
<dd><p>Specifies a pointer to an Image structure.  Reduce
image to a set of colors represented by this image.</p>
</dd>
<dt>dither:</dt>
<dd><p>Set this integer value to something other than zero to
dither the quantized image.</p>
</dd>
</dl>
</section>
</section>
<section id="mapimages">
<h1><a class="toc-backref" href="#id28">MapImages</a></h1>
<section id="id13">
<h2>Synopsis</h2>
<pre class="literal-block">unsigned int MapImages( <a class="reference external" href="../api/types.html#image">Image</a> *images, <a class="reference external" href="../api/types.html#image">Image</a> *map_image, const unsigned int dither );</pre>
</section>
<section id="id14">
<h2>Description</h2>
<p>MapImages() replaces the colors of a sequence of images with the closest
color from a reference image. If the reference image does not contain a
colormap, then a colormap will be created based on existing colors in the
reference image. The order and number of colormap entries does not match
the reference image.  If the order and number of colormap entries needs to
match the reference image, then the ReplaceImageColormap() function may be
used after invoking MapImages() in order to apply the reference colormap.</p>
<p>The format of the MapImage method is:</p>
<pre class="literal-block">unsigned int MapImages( <a class="reference external" href="../api/types.html#image">Image</a> *images, <a class="reference external" href="../api/types.html#image">Image</a> *map_image, const unsigned int dither );</pre>
<dl class="simple">
<dt>image:</dt>
<dd><p>Specifies a pointer to a set of Image structures.</p>
</dd>
<dt>map_image:</dt>
<dd><p>Specifies a pointer to an Image structure.  Reduce
image to a set of colors represented by this image.</p>
</dd>
<dt>dither:</dt>
<dd><p>Set this integer value to something other than zero to
dither the quantized image.</p>
</dd>
</dl>
</section>
</section>
<section id="orderedditherimage">
<h1><a class="toc-backref" href="#id29">OrderedDitherImage</a></h1>
<section id="id15">
<h2>Synopsis</h2>
<pre class="literal-block">unsigned int OrderedDitherImage( <a class="reference external" href="../api/types.html#image">Image</a> *image );</pre>
</section>
<section id="id16">
<h2>Description</h2>
<p>OrderedDitherImage() uses the ordered dithering technique of reducing color
images to monochrome using positional information to retain as much
information as possible.</p>
<p>The format of the OrderedDitherImage method is:</p>
<pre class="literal-block">unsigned int OrderedDitherImage( <a class="reference external" href="../api/types.html#image">Image</a> *image );</pre>
<p>A description of each parameter follows.</p>
<dl class="simple">
<dt>image:</dt>
<dd><p>Specifies a pointer to an Image structure;  returned from
ReadImage.</p>
</dd>
</dl>
</section>
</section>
<section id="quantizeimage">
<h1><a class="toc-backref" href="#id30">QuantizeImage</a></h1>
<section id="id17">
<h2>Synopsis</h2>
<pre class="literal-block">unsigned int QuantizeImage( const <a class="reference external" href="../api/types.html#quantizeinfo">QuantizeInfo</a> *quantize_info, <a class="reference external" href="../api/types.html#image">Image</a> *image );</pre>
</section>
<section id="id18">
<h2>Description</h2>
<p>QuantizeImage() analyzes the colors within a reference image and chooses a
fixed number of colors to represent the image.  The goal of the algorithm
is to minimize the color difference between the input and output image while
minimizing the processing time.</p>
<p>The format of the QuantizeImage method is:</p>
<pre class="literal-block">unsigned int QuantizeImage( const <a class="reference external" href="../api/types.html#quantizeinfo">QuantizeInfo</a> *quantize_info, <a class="reference external" href="../api/types.html#image">Image</a> *image );</pre>
<dl class="simple">
<dt>quantize_info:</dt>
<dd><p>Specifies a pointer to an QuantizeInfo structure.</p>
</dd>
<dt>image:</dt>
<dd><p>Specifies a pointer to an Image structure.</p>
</dd>
</dl>
</section>
</section>
<section id="quantizeimages">
<h1><a class="toc-backref" href="#id31">QuantizeImages</a></h1>
<section id="id19">
<h2>Synopsis</h2>
<pre class="literal-block">unsigned int QuantizeImages( const <a class="reference external" href="../api/types.html#quantizeinfo">QuantizeInfo</a> *quantize_info, <a class="reference external" href="../api/types.html#image">Image</a> *images );</pre>
</section>
<section id="id20">
<h2>Description</h2>
<p>QuantizeImages() analyzes the colors within a set of reference images and
chooses a fixed number of colors to represent the set.  The goal of the
algorithm is to minimize the color difference between the input and output
images while minimizing the processing time.</p>
<p>The format of the QuantizeImages method is:</p>
<pre class="literal-block">unsigned int QuantizeImages( const <a class="reference external" href="../api/types.html#quantizeinfo">QuantizeInfo</a> *quantize_info, <a class="reference external" href="../api/types.html#image">Image</a> *images );</pre>
<dl class="simple">
<dt>quantize_info:</dt>
<dd><p>Specifies a pointer to an QuantizeInfo structure.</p>
</dd>
<dt>images:</dt>
<dd><p>Specifies a pointer to a list of Image structures.</p>
</dd>
</dl>
</section>
</section>
</main>


<hr class="docutils">
<div class="document">
    <p><a href="../Copyright.html">Copyright</a> © GraphicsMagick Group 2002-2025<!--SPONSOR_LOGO--></p>
</div>

</main>
</body>
</html>
